<template>
  <view class="data-item">
    <view class="data-label">
      <view class="data-icon" :class="iconBgClass">
        <u-icon :name="icon" :color="iconColor" size="16"></u-icon>
      </view>
      <text>{{ label }}</text>
    </view>
    
    <view class="data-value">
      {{ value }}<text v-if="unit" class="data-unit">{{ unit }}</text>
    </view>
  </view>
</template>

<script setup lang="ts">
import { computed } from 'vue';

// 定义颜色类型
type ColorType = 'pink' | 'blue' | 'green' | 'red';

// 定义props
const props = defineProps({
  icon: {
    type: String,
    required: true
  },
  label: {
    type: String,
    required: true
  },
  value: {
    type: [String, Number],
    required: true
  },
  unit: {
    type: String,
    default: ''
  },
  color: {
    type: String as () => ColorType,
    default: 'pink'
  }
});

// 计算图标背景类
const iconBgClass = computed(() => {
  const colorMap: Record<ColorType, string> = {
    pink: 'bg-pink-100',
    blue: 'bg-blue-100',
    green: 'bg-green-100',
    red: 'bg-red-100'
  };
  return colorMap[props.color as ColorType] || 'bg-pink-100';
});

// 计算图标颜色
const iconColor = computed(() => {
  const colorMap: Record<ColorType, string> = {
    pink: '#FF9FB5',
    blue: '#64B5F6',
    green: '#81C784',
    red: '#F87171'
  };
  return colorMap[props.color as ColorType] || '#FF9FB5';
});
</script>

<style lang="scss" scoped>
.data-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.data-label {
  display: flex;
  align-items: center;
}

.data-icon {
  width: 40rpx;
  height: 40rpx;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-right: 10rpx;
}

.bg-pink-100 {
  background-color: rgba(255, 159, 181, 0.1);
}

.bg-blue-100 {
  background-color: rgba(96, 165, 250, 0.1);
}

.bg-green-100 {
  background-color: rgba(16, 185, 129, 0.1);
}

.bg-red-100 {
  background-color: rgba(248, 113, 113, 0.1);
}

.data-value {
  font-size: 32rpx;
  font-weight: bold;
  color: #333;
}

.data-unit {
  font-size: 24rpx;
  font-weight: normal;
  color: #999;
  margin-left: 4rpx;
}
</style> 